package org.hu.controller;

import lombok.extern.slf4j.Slf4j;
import org.hu.entity.vo.Result;
import org.hu.service.WxLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("")
@Slf4j
public class WxLoginController {

    @Autowired
    private WxLoginService wxLoginService;

    @PostMapping(value = "/wxlogin",produces = "application/json")
    public Map<String, Object> wxLogin(@RequestBody Map<String, String> body) {
        String code = body.get("code");
        String token = wxLoginService.login(code);
        Map<String, Object> result = new HashMap<>();
        result.put("token", token);
        log.info("给前端的信息:{}", result);
        return result;
    }

}
